package com.lxt.basicmvc;

import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;

import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.lxt.basicmvc.bean.BingImg;
import com.lxt.basicmvc.net.Api;
import com.lxt.basicmvc.net.ApiService;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author joyson
 * @create 2020-09-21
 */
public class MainActivity extends AppCompatActivity {
    @BindView(R.id.tv_content)
    TextView tvContent;
    private String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        tvContent.setText("哈哈哈哈");
        Api.get("https://cn.bing.com/")
                .create(ApiService.class)
                .getBingImgLiveData().observe(this, new Observer<BingImg>() {
            @Override
            public void onChanged(BingImg bingImg) {
                Log.d(TAG, "onChanged: 请求结果：" + new Gson().toJson(bingImg));
                Toast.makeText(MainActivity.this, "hah", Toast.LENGTH_LONG).show();
            }
        });

        Api.get("https://cn.bing.com/")
                .create(ApiService.class)
                .getBingImgLiveDataS().observe(this, new Observer<String>() {
            @Override
            public void onChanged(String response) {
                Log.d(TAG, "onChanged 22: 请求结果：" + response);
            }
        });

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                ToastUtils.showShort("呵呵呵呵呵呵呵呵呵呵");
            }
        }, 2000);

    }
}
